class ListaPrecioController < ApplicationController

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def index
    list
    
    render :action => 'list'
  
  end

  def list
    @precios = ListaPrecio.paginate :page => params[:page], :per_page => DEFAULT_PER_PAGE, :order => 'producto_id, litraje_mls'

  end

  def new
    @precio = ListaPrecio.new
    @productos = Producto.find(:all, :order => 'descripcion')
    @litrajes = Catalogo.find_by_nombre('Litraje').entradas_catalogo

  end

  def create
    @precio = ListaPrecio.new(params[:precio])

    if @precio.save
      flash[:notice] = "Precio was successfully created."
      redirect_to :action => 'list'
    else
      @productos = Producto.find(:all, :order => 'descripcion')
      @litrajes = Catalogo.find_by_nombre('Litraje').entradas_catalogo
      render :action => 'new'

    end

  end

  def edit
    @precio = ListaPrecio.find(params[:id])

  end

  def update
    @precio = ListaPrecio.find(params[:id])

    if @precio.update_attributes(params[:precio])
      flash[:notice] = "Precio was successfully update."
      redirect_to :action => 'list'
    else
      render :action => 'edit'

    end

  end

end
